package org.school.streaming.net.client.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.school.streaming.net.RequestType;
import org.school.streaming.net.State;
import org.school.streaming.net.client.Client;

/**
 * @authors Jeffrey Goudzwaard,
 * 			Davin Terrizzi
 * @version	1.0
 * @date	18-4-2013
 */

/**
 * Class representing ActionListener behind PLAY button in Client GUI
 * @author Davin
 *
 */
public class btnPlayListener implements ActionListener
{
	@Override
	public void actionPerformed( ActionEvent ae )
	{
		System.out.println( "Play Button pressed!" );
		
		// Get Client instance
		Client client = Client.getClient();
		
		// Check Client state and send right request accordingly
		// Start timer if started server succesfully and set new state
		if( client.getState() == State.READY )
		{
			client.sendRequest( RequestType.PLAY );
			
			if( client.parseServerResponse() != 200 )
			{
				System.err.println( "Error 100: Invalid Server Response!" );
			}
			else
			{
				client.getTimer().start();
				client.setState( State.PLAYING );
				System.out.println( "New RTSP state: PLAYING" );
			}
		}
	}
}
